<script>
//import _axios from "@/plugins/axios";
import request from "@/utils/request";
//import Aside from "@/components/Aside.vue";
//import Header from "@/components/Header.vue";
//import Manager from "./Manager.vue";
export default {
  name: "LoginDetails",
  data() {
    return {
      tableData: [],
      total: 0,
      pageNum: 1,
      pageSize: 5,
      id: '',
      nowID:'',
      dialogFormVisible: false,
      formLabelWidth:'100px',
      form: {
        account: '',
        password: '',
        userType: '',
      },
      multipleSelection: [],

    }
  },
  created() {
    //请求分页查询数据
    this.load()
  },
  //  components: {
  //   Aside,
  //   Header,
  //   Manager
  // },
  methods: {
    reset() {
      this.id = ""
      this.load()
    },
    load() {
      request.post("/LoginDetails/getLoginPage", {
              pageNum: this.pageNum,
              pageSize: this.pageSize,
              id: this.id
          }
      ).then(res => {
        console.log(res)
        this.tableData = res.data.result
        this.total = res.data.total
      })
    },
    loadForOne() {
      request.post("/LoginDetails/query", {
            pageNum: this.pageNum,
            pageSize: this.pageSize,
            id: this.id
          }
      ).then(res => {
        console.log(res)
        this.tableData = res.data.result
        this.total =res.data.total
      })
    },
    handleSizeChange(pageSize) {
      console.log(pageSize)
      this.pageSize = pageSize
      this.load()
    },
    handleCurrentChange(pageNum) {
      console.log(pageNum)
      this.pageNum = pageNum
      this.load()
    },
    handleAdd() {
      this.dialogFormVisible = true
      this.form = {}
    },
    save() {
      if(!this.nowID){
      request.post("/LoginDetails/insert", this.form).then(res => {
        if (res) {
          this.$message.success("保存成功")
          this.dialogFormVisible = false
          this.load()
        } else {
          this.$message.error("保存失败")
        }
      })}
      else {
        request.post("/LoginDetails/update", this.form, this.nowID).then(res => {
          if (res) {
            this.$message.success("保存成功")
            this.dialogFormVisible = false
            this.load()
          } else {
            this.$message.error("保存失败")
          }

        })
      }
    },
    handleEdit(row) {
      this.form = row
      this.dialogFormVisible = true
      this.form = Object.assign({}, row)
    },
    handleDelete(id) {
      request.post("/LoginDetails/remove" , this.form,id).then(res => {
        if (res) {
          this.$message.success("删除成功")
          this.dialogFormVisible = false
          this.load()
        } else {
          this.$message.error("删除失败")
        }
      })
    },

    handleSelectionChange(val) {
      console.log(val)
      this.multipleSelection = val
    },

    /*deleteBatch(){
      let ids= this.multipleSelection.map(v =>v.name)//把对象数组变成纯name的数组
      _axios.post("/Pet/del/batch",ids).then(res=>{
        if(res){
          this.$message.success("批量删除成功")
          this.dialogFormVisible=false
          this.load()
        }
        else {
          this.$message.error("批量删除失败")
        }
      })
    },*/
  }
}
</script>

<template>
  <div>
    <div style="margin-bottom: 30px">

    </div>

    <div style="padding: 10px 0">
      <el-input v-model="id" style="width: 200px" placeholder="请输入用户id" suffix-icon="el-icon-zoom-in"></el-input>
      <!--            <el-button style="margin-left: 5px" type="primary" @click="load">搜索</el-button>-->
      <!--            <el-input v-model="research_direction"style="width: 200px;margin-left: 5px" placeholder="请输入研究方向" suffix-icon="el-icon-office-building"></el-input>-->
      <!--            <el-button style="margin-left: 5px" type="primary" @click="load">搜索</el-button>-->
      <!--            <el-input v-model="work_place"style="width: 200px;margin-left: 5px" placeholder="请输入办公室" suffix-icon="el-icon-office-building"></el-input>-->
      <el-button style="margin-left: 5px" type="primary" @click="loadForOne">搜索</el-button>
      <el-button style="margin-left: 5px" type="info" @click="reset">重置</el-button>
    </div>


    <div class="container">
      <el-table :data="tableData" border stripe @selection-change="handleSelectionChange">
        <el-table-column prop="id" label="用户id" width="70">
        </el-table-column>
        <el-table-column prop="account" label="账号" width="300">
        </el-table-column>
        <el-table-column prop="password" label="密码" width="300">
        </el-table-column>
        <el-table-column prop="userType" label="账户类型" width="80">
        </el-table-column>
        <el-table-column>
          <template slot-scope="scope">
            <el-button type="success" @click="handleEdit(scope.row)" >编辑<i class="el-icon-edit"></i></el-button>
            <el-popconfirm
                style="margin-left: 5px"
                confirm-button-text='确定'
                cancel-button-text='再想想'
                icon="el-icon-info"
                icon-color="red"
                title="确定删除吗？"
                @confirm="handleDelete(scope.row.id)"
            >
              <el-button type="danger" slot="reference">删除<i class="el-icon-remove-outline"></i></el-button>
            </el-popconfirm>
          </template>
        </el-table-column>
      </el-table>
      <div style="padding: 10px 0">
        <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="pageNum"
            :page-sizes="[5, 10, 15, 20]"
            :page-size="pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total">
        </el-pagination>
      </div>
      <!-- Form -->
    </div>
  </div>
</template>

<style scoped>
.container {
  height: 100%;
  position: relative;
  padding-bottom: 50px; /* 底部留出足够的空间来容纳固定的元素 */
}

.el-pagination {
  position: fixed;
  bottom: 0;
}

</style>